// custom-tab-bar/index.js
import {storeBindingsBehavior} from 'mobx-miniprogram-bindings'
import {store} from '../store/store'
Component({
  options:{
    styleIsolation: 'shared'
  },
  observers:{
    'sum':function (newVal) {
      console.log(newVal)
      this.setData({
        'list[1].info':newVal
      })
    }
  },
  behaviors:[storeBindingsBehavior],
  storeBindings:{
    //数据源
    store, //指定要绑定的Store
    fields:{  //指定要绑定的字段数据
      // 自定义名字：'共享数据的名字'
      sum:'sum',    //绑定字段的第3种方式
      active: 'activeTabBarIndex'
    },
    actions:{  //指定要绑定的方法
      updataActive:'updataActiveTabBarIndex'
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    "list": [{
      "pagePath": "/pages/home/home",
      "text": "首页",
      "iconPath": "/images/home.png",
      "selectedIconPath": "/images/home-active.png"
    },{
      "pagePath": "/pages/message/message",
      "text": "消息",
      "iconPath": "/images/message.png",
      "selectedIconPath": "/images/message-active.png",
      info:2
    },{
      "pagePath": "/pages/contact/contact",
      "text": "联系我们",
      "iconPath": "/images/contact.png",
      "selectedIconPath": "/images/contact-active.png"
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      // this.setData({ active: event.detail });
      this.updataActive(event.detail)
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },
  }
})
